package com.sgb.kjwl.view.ui.adapter.enterprise;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.core.util.Pair;

import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemPropertyListMakeoverBinding;
import com.sgb.kjwl.model.entity.enterprise.PropertyEntity;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.utils.DialogFunction;
import com.sgb.kjwl.utils.DialogHelper;
import com.sgb.kjwl.utils.PointUtils;
import com.swgk.core.event.EventConstant;
import com.sgb.kjwl.view.ui.activity.enterprise.MakeOverDetailActivity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class PropertyAdapter extends BaseRecycleAdapter<PropertyEntity> {
    Context context;

    public PropertyAdapter(Context context, List<PropertyEntity> datas) {
        super(context, R.layout.item_property_list_makeover, datas);

        this.context = context;
    }

    @Override
    public void convert(ItemViewHolder holder, PropertyEntity propertyEntity) {
        ItemPropertyListMakeoverBinding itemCompanyListBinding = (ItemPropertyListMakeoverBinding) holder.getmBinding();
        itemCompanyListBinding.setProperty(propertyEntity);
        TextView tv_tag = holder.getItem().findViewById(R.id.tv_item_intel_prop_publish);
        switch (propertyEntity.getPublishType()) {
            case 0://个人
                tv_tag.setText("个人");
                tv_tag.setBackgroundResource(R.drawable.shape_radius_1_solid_bule);
                break;
            case 1://企业
                tv_tag.setText("企业");
                tv_tag.setBackgroundResource(R.drawable.shape_radius_1_solid_bule);
                break;
            case 2://团队
                tv_tag.setText("团队");
                tv_tag.setBackgroundResource(R.drawable.ractangle_radius_1_solid_yellow);
                break;
            default:
                tv_tag.setVisibility(View.GONE);
                break;
        }
        if (propertyEntity.getLabel() != null && propertyEntity.getLabel().contains("1")) {
            holder.setVisible(R.id.tv_item_intel_prop_hot, true);
        } else {
            holder.setVisible(R.id.tv_item_intel_prop_hot, false);
        }
        if (propertyEntity.getLabel() != null && propertyEntity.getLabel().contains("2")) {
            holder.setVisible(R.id.tv_item_intel_prop_urgent_sale, true);
        } else {
            holder.setVisible(R.id.tv_item_intel_prop_urgent_sale, false);
        }

        itemCompanyListBinding.tvItemTradeType.setText(TextViewBindingAdapter.setTextForColon("资产类型:"+(propertyEntity.getTypeName().equals("") ? "/" : propertyEntity.getTypeName())));
        itemCompanyListBinding.tvItemRatePayType.setText(TextViewBindingAdapter.setTextForColon("买入价:"+ ((propertyEntity.getBuyingPrice() > 0) ?PointUtils.price(propertyEntity.getBuyingPrice()) +"元":"/")));

        itemCompanyListBinding.btnChat.setOnClickListener(v -> {
            if (!DialogHelper.checkLogin()){
                DialogHelper.showLoginDialogNew(context, EventConstant.EVENT_MAKE_OVER_JUMP,"温馨提示", "登录后可拨打电话,去登录", "登录");
                return;
            }
            DialogHelper.showDialog(context, "确认呼叫", propertyEntity.getLinkman()+":"+propertyEntity.getContactNumber(), "确定", new DialogFunction() {
                @Override
                public void normalRoundDialog() {
                    ActivityJump.jumpToPhone(context,propertyEntity.getContactNumber());
                }
            });
        });

        holder.itemView.setOnClickListener(v -> ActivityJump.jumpToActivity(context, MakeOverDetailActivity.class, Pair.create("detail","资产"),Pair.create("id",propertyEntity.getId())));
    }


}
